<?php
		global $_W, $_GPC;
			load()->func('tpl');
		$operation = !empty($_GPC['op']) ? $_GPC['op'] : 'display';
		if ($operation == 'display') {
			$list = pdo_fetchall("SELECT * FROM " . tablename('bbyscm_card_banner') . " WHERE uniacid = '{$_W['uniacid']}' ORDER BY displayorder DESC");
		} elseif ($operation == 'post') {
			$id = intval($_GPC['id']);
			if (checksubmit('submit')) {
				$data = array(
					'uniacid' => $_W['uniacid'],
					'advname' => $_GPC['advname'],
					'link' => $_GPC['link'],
					'enabled' => intval($_GPC['enabled']),
					'displayorder' => intval($_GPC['displayorder']),
					'thumb'=>$_GPC['thumb'],
					'wx_appid' => $_GPC['wx_appid'],
					'wx_path' => $_GPC['wx_path'],
					'start_time'=> strtotime($_GPC['activity']['start']),
		            'end_time'=> strtotime($_GPC['activity']['end']),
					'createtime' => time(),
				);
				if (!empty($id)) {
					pdo_update('bbyscm_card_banner', $data, array('id' => $id));
				} else {
					pdo_insert('bbyscm_card_banner', $data);
					$id = pdo_insertid();
				}
				message('更新幻灯片成功！', $this->createWebUrl('banner', array('op' => 'display')), 'success');
			}
			$banner = pdo_fetch("select * from " . tablename('bbyscm_card_banner') . " where id=:id and uniacid=:uniacid limit 1", array(":id" => $id, ":uniacid" => $_W['uniacid']));
		} elseif ($operation == 'delete') {
			$id = intval($_GPC['id']);
			$banner = pdo_fetch("SELECT id FROM " . tablename('bbyscm_card_banner') . " WHERE id = '$id' AND uniacid=" . $_W['uniacid'] . "");
			if (empty($banner)) {
				message('抱歉，幻灯片不存在或是已经被删除！', $this->createWebUrl('banner', array('op' => 'display')), 'error');
			}
			pdo_delete('bbyscm_card_banner', array('id' => $id));
			message('幻灯片删除成功！', $this->createWebUrl('banner', array('op' => 'display')), 'success');
		} else {
			message('请求方式不存在');
		}
		include $this->template('web/banner');
	
